package com.yupi.yuso.designpattern.register;

import com.yupi.yuso.common.ErrorCode;
import com.yupi.yuso.designpattern.adapter.DataSourceTarget;
import com.yupi.yuso.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author vvv
 * @date 2023-12-21 22 28
 * discription
 */
public class DataSourceRegister {
    public static final ConcurrentHashMap<String, DataSourceTarget<?>> SEARCH_MAP = new ConcurrentHashMap<>();

    public static DataSourceTarget<?> getDataSourceBy(String type) {
        if (StringUtils.isBlank(type)) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR);
        }
        return SEARCH_MAP.get(type);
    }

    public static Collection<DataSourceTarget<?>> getAllDataSource() {
        return SEARCH_MAP.values();
    }
}